package com.jusfoun.communication.aop;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登陆拦截
 *
 * @author player six
 * @email jslcylcy@163.com
 * @create 2018-01-29 14:39
 **/
public class LoginInterceptor extends HandlerInterceptorAdapter {

    private static final Logger LOGGER = LoggerFactory.getLogger(LoginInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (!request.getServletPath().contains("login") && null == request.getSession().getAttribute("user")) {
            LOGGER.info("url:"+request.getServletPath());
            LOGGER.info("跳转登录页面");
            response.sendRedirect(request.getContextPath() + "/index/login");
            return false;
        }
        return true;
    }

}
